package com.rampage.entity.user;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.rampage.entity.IdEntity;
import com.rampage.entity.role.Role;

import javax.persistence.*;
import java.util.Set;

/**
 * 用户
 * Created by wujingwei on 2017/12/18.
 */
@Entity
@Table(name = "t_user")
public class User extends IdEntity{

    private String username;
    private String password;
    private boolean enable = true;
    private Set<Role> roles;

    @Column(unique = true, nullable = false)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(nullable = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(nullable = false)
    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "t_user_role", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")})
    @OrderBy("id")
    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }
}
